import axios from 'axios';
const mutations = {
    /**
     * 助力者生成海报的信息
     * @param {}} state 
     * @param {*} data 
     */
    saveAssitorInfo(state, data) {
        let callback;
        if (data && data.hasOwnProperty("callback")) {
            callback = data.callback;
            delete (data.callback);
        }
        axios.post('/api/user/saveZhuli',data)
        .then(function (response) {
            /**
             * 如果存在回调
             * @param  {Function} callback [description]
             * @return {[type]}            [description]
             */
            if (callback) {
                callback(response.data, data);
            }
        })
    },
    /**
     * 获取助力者信息
     * @param {*} state 
     * @param {*} data 
     */
    getAssitorInfo(state,data){
        let callback;
        if (data && data.hasOwnProperty("callback")) {
            callback = data.callback;
            delete (data.callback);
        }
        axios.get('/api/user/getZhuli',{
            params:data
        })
        .then(function (response) {
            /**
             * 如果存在回调
             * @param  {Function} callback [description]
             * @return {[type]}            [description]
             */
            console.log(response)
            state.assitorInfo = response.data.data;
            if (callback) {
                callback(response.data, data);
            }
        })
    },
    /**
     * 保存志愿者信息
     * @param {*} state 
     * @param {*} data 
     */
    saveVolunteerInfo(state, data) {
        let callback;
        if (data && data.hasOwnProperty("callback")) {
            callback = data.callback;
            delete (data.callback);
        }
        axios.post('/api/user/saveVolunteer',data)
        .then(function (response) {
            /**
             * 如果存在回调
             * @param  {Function} callback [description]
             * @return {[type]}            [description]
             */
            if (callback) {
                callback(response.data, data);
            }
        })
    },
    saveVolunteerPoster(state, data) {
        let callback;
        if (data && data.hasOwnProperty("callback")) {
            callback = data.callback;
            delete (data.callback);
        }
        axios.post('/api/user/saveVolunteerPoster',data)
        .then(function (response) {
            /**
             * 如果存在回调
             * @param  {Function} callback [description]
             * @return {[type]}            [description]
             */
            if (callback) {
                callback(response.data, data);
            }
        })
    },
    /**
     * 获取志愿者信息
     * @param {*} state 
     * @param {*} data 
     */
    getVolunteerInfo(state,data){
        let callback;
        if (data && data.hasOwnProperty("callback")) {
            callback = data.callback;
            delete (data.callback);
        }
        axios.get('/api/user/getVolunteer',{
            params:data
        })
        .then(function (response) {
            /**
             * 如果存在回调
             * @param  {Function} callback [description]
             * @return {[type]}            [description]
             */
            console.log(response)
            state.assitorInfo = response.data.data;
            if (callback) {
                callback(response.data, data);
            }
        })
    },
    /**
     * 获取分享信息
     * @param {*} state 
     * @param {*} data 
     */
    getShareInfo(state,data){
        let callback;
        if (data && data.hasOwnProperty("callback")) {
            callback = data.callback;
            delete (data.callback);
        }
        axios.get('/api/auth/getShareInfo',{
            params:data
        })
        .then( (response)=> {
            /**
             * 如果存在回调
             * @param  {Function} callback [description]
             * @return {[type]}            [description]
             */
            state.shareInfo = response.data.data;
            if (callback) {
                callback(response.data, data);
            }
        })
    },
    /**
     * 志愿者身份证识别
     * @param {} state 
     * @param {*} data 
     */
    uploadUserIdcard(state,data){
        let callback;
        if (data && data.hasOwnProperty("callback")) {
            callback = data.callback;
            delete (data.callback);
        }
        axios.post('/api/user/cardOcr',data)
        .then( (response)=> {
            /**
             * 如果存在回调
             * @param  {Function} callback [description]
             * @return {[type]}            [description]
             */
            if (callback) {
                callback(response.data, data);
            }
        })
    },
    getUserInfoFn(state,data){
        let callback;
        if (data && data.hasOwnProperty("callback")) {
            callback = data.callback;
            delete (data.callback);
        }
        axios.post('/api/auth/getUserByCode',data)
        .then( (response)=> {
            /**
             * 如果存在回调
             * @param  {Function} callback [description]
             * @return {[type]}            [description]
             */
            if (callback) {
                callback(response.data, data);
            }
        })
    },
}
export default mutations;